import { dealDataExcept } from "@/utils/common";

/**
 * 获取商品进价
 * @param goodsSpecList 商品规格
 * @returns
 */
export const getPrice = goodsSpec => {
  let price = 0;
  if (goodsSpec && goodsSpec.brandRel) {
    price = dealDataExcept(goodsSpec.brandRel.storeBuyPrice) || 0;
  }
  return price;
};

/**
 * 获取商品库存
 * @param goodsSpecList 商品规格
 * @returns
 */
export const getStock = stockItemList => {
  let tempList = stockItemList || [];
  return tempList
    .map(v => v.canUseNum || 0)
    .reduce((total, current) => total + current, 0);
};

/**
 * 获取供应商库存
 * @param goodsSpecList 商品规格
 * @returns
 */
export const getSupplierStock = stockSupplierList => {
  let tempList = stockSupplierList || [];
  return tempList
    .map(v => v.leaveNum || 0)
    .reduce((total, current) => total + current, 0);
};
